/*****************************************************************
Mix3D WebGL Game Engine
Copyright (c) fantasy ( fantasy.x2x@gmail.com )
Listens:
Distributed under the Boost Software License, Version 1.0.
http://www.boost.org/LICENSE_1_0.txt
 ****************************************************************/
/**
 * @Desc    : Common tools
 * @Author  : fantasy(fantasy.x2x@gmail.com)
 **/
//////////////////////////////////////////////////////////////////
// namespace check
if(typeof(Mix3D) === 'undefined')
{
  Mix3D = {};
};
(function(Mix3D){
//////////////////////////////////////////////////////////////////
/**
 * @Desc : console output message
 **/
Mix3D.log = function( msg )
{
  if(console && console.log )console.log("Mix3D log: " + msg ); 
}
Mix3D.warning = function( warning )
{
  if(console && console.log )console.warn("Mix3D warning: " + warning);
}
Mix3D.error = function( error )
{
  if(console && console.error )console.error("Mix3D error: " + error);
}

/**
 * @Desc : string hashing function 
 **/
Mix3D.strHash = function( str )
{
  var hash = 5381;
  for( var i=0; i<str.length; ++i)
  { hash = ((hash << 5) + hash) + str[i]; }
  return hash;
}
 
/**
 * @Desc : Create GUID
 **/
Mix3D.createGUID = function()
{
  var key1="0123456789ABCDEF", key2="89AB", guid="";
	for(var i=0;i<38;++i)
	{
		switch(i)
		{
			case 8:guid=guid+"-";break;
			case 13:guid=guid+"-";break;
			case 18:guid=guid+"-";break;
			case 14:guid=guid+"4";break;
			case 19:guid=guid+key1[Math.round(Math.random()*3)];break;
			default:guid=guid+key2[Math.round(Math.random()*15)];break;
		}
	}
	return guid;
}
//////////////////////////////////////////////////////////////////
})(Mix3D);// end of function(Mix3D)